import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home/index'),
        meta: { title: '首页' }
      },
      {
        path: 'editPassword',
        name: 'editPassword',
        component: () => import('@/views/login/password'),
        meta: { title: '修改密码' }
      },
      {
        path: '/404',
        component: () => import('@/views/error-page/404'),
        meta: { title: '404' }
      },
      {
        path: '/403',
        component: () => import('@/views/error-page/403'),
        meta: { title: '无权限访问' }
      }
    ]
  },
  {
    path: '/system',
    name: 'system',
    component: Layout,
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user'),
        meta: { title: '用户管理' }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role'),
        meta: { title: '角色管理' }
      },
      {
        path: 'role/auth/:id',
        name: 'allotAuth',
        component: () => import('@/views/system/auth/allot'),
        meta: { title: '分配权限' }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu'),
        meta: { title: '菜单管理' }
      },
      {
        path: 'auth',
        name: 'auth',
        component: () => import('@/views/system/auth'),
        meta: { title: '权限管理' }
      }
      // {
      //   path: 'dictionary',
      //   name: 'dictionary',
      //   component: () => import('@/views/system/dictionary'),
      //   meta: { title: '字典管理' }
      // },
      // {
      //   path: '/icon',
      //   name: 'icon',
      //   component: () => import('@/views/system/icons')
      // },
    ]
  },
  {
    path: '/member',
    name: 'member',
    component: Layout,
    children: [
      {
        path: 'fans',
        name: 'fans',
        component: () => import('@/views/member/fans')
      },
      {
        path: 'member',
        name: 'member',
        component: () => import('@/views/member/member')
      }
    ]
  }
]
export const LocalFixRoutes = [
  {
    path: '/wechatServicer',
    name: 'wechatServicer',
    meta: {
      icon: 'hy-caidan',
      title: '服务号管理'
    },
    component: Layout,
    children: [
      {
        path: 'menuContr',
        name: 'menuContr',
        component: () => import('@/views/servicePage/menuManage/index'),
        meta: { icon: 'el-icon-menu', title: '服务号菜单' }
      },
      // 新增/编辑
      {
        path: 'menuContr/menu/:id',
        name: 'menuContr-menu',
        component: () => import('@/views/servicePage/menuManage/menu'),
        meta: { hidden: true, title: '设置菜单' }
      },
      {
        path: 'signContr',
        name: 'signContr',
        component: () => import('@/views/servicePage/signManage/index'),
        meta: { icon: 'hy-sign', title: '会员标签' }
      },
      {
        path: 'resourceContr',
        name: 'resourceContr',
        component: () => import('@/views/servicePage/resourceManage/index'),
        meta: { icon: 'hy-fans', title: '资源中心' }
      }
    ]
  },
  {
    path: '/skinDisease',
    name: 'skinDisease',
    component: Layout,
    children: [
      {
        path: 'collocate',
        name: 'collocate',
        component: () => import('@/views/skinDisease/collocate')
      },
      {
        path: 'rankdoc',
        name: 'rankdoc',
        component: () => import('@/views/skinDisease/rankdoc')
      },
      {
        path: 'case',
        name: 'case',
        component: () => import('@/views/skinDisease/case')
      },
      {
        path: 'caseDetail',
        name: 'caseDetail',
        component: () => import('@/views/skinDisease/case/caseDetail/caseDetail'),
        meta: { title: '案例详情' }
      },
      {
        path: 'compete',
        name: 'compete',
        component: () => import('@/views/skinDisease/compete')
      },
      {
        path: 'final',
        name: 'final',
        component: () => import('@/views/skinDisease/final')
      },
      {
        path: 'learn',
        name: 'learn',
        component: () => import('@/views/skinDisease/learn')
      },
      {
        path: 'rankstu',
        name: 'rankstu',
        component: () => import('@/views/skinDisease/rankstu')
      }
    ]
  },
  {
    path: '/general',
    name: 'general',
    component: Layout,
    children: [
      {
        path: 'collocate',
        name: 'collocate',
        component: () => import('@/views/skinDisease/collocate')
      }
    ]
  }
]
const allRouter = constantRoutes.concat(LocalFixRoutes)
const createRouter = () =>
  new Router({
    mode: 'hash', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: allRouter
  })

const router = createRouter()

// 清除之前添加的动态路由信息
export function resetRouter() {
  router.options.routes = allRouter // reset router
}

export default router
